
class SingletonLazy{
    private static volatile SingletonLazy instance=null;//3、volatile

    public static SingletonLazy getInstance(){
        if(instance==null){
            synchronized (SingletonLazy.class){//1、正确加锁
                if (instance==null)//2、双重判断
                    instance=new SingletonLazy();
            }
        }
        return instance;
    }

    private SingletonLazy(){}
}


public class Test1 {

    public static void main(String[] args) {

    }
}
